package pages;

import core.TestBase;
import org.openqa.selenium.By;
import org.testng.Assert;
import ui_tests.TestData;
import utils.Log4Test;

/**
 * Created by w on 09.07.14.
 */
public class ApplePage extends TestBase {
    protected By arrowSortView = By.xpath(".//*[@id='sort_view']/a/i");
    protected By expensiveCheapSort = By.xpath(".//*[@id='sort_view']//a[contains(text(),'от дорогих к дешевым')]");
    protected By searchedMacBookName_Z0PU002JE = By.xpath(".//div[@class='gtile-i-title']/a[contains(text(),'Z0PU002JE')]/../..");
    protected By toComparisonCheckboxMacBookName_Z0PU002JE = By.xpath(".//div[@class='gtile-i-title']/a[contains(text(),'Z0PU002JE')]/../..//input[@type='checkbox']");
    protected By toComparisonAdded_Z0PU002JE = By.xpath(".//div[@class='block']//a[contains(text(),'"+TestData.MacBookZ0PU002JE+"')]");
    protected By searchedMacBookName_ME294UA = By.xpath(".//div[@class='gtile-i-title']/a[contains(text(),'ME294UA/A')]/../..");
    protected By toComparisonCheckboxMacBookName_ME294UA = By.xpath(".//div[@class='gtile-i-title']/a[contains(text(),'ME294UA/A')]/../..//input[@type='checkbox']");
    protected By toComparisonAdded_ME294UA = By.xpath(".//div[@class='block']//a[contains(text(),'"+ TestData.MacBookME294UA+"')]");
protected By toComparisonClick_Z0PU002JE=By.xpath(".//div[@class='gtile-i-title']/a[contains(text(),'Z0PU002JE')]/../..//a[@class='lightblue underline']");
    public void verifyApplePage() {
        Log4Test.info("Verify ApplePage");
/*
        System.out.println(webDriver.getCurrentUrl());
*/
        Assert.assertEquals(webDriver.getCurrentUrl().contains("apple"), true);
/*
        Assert.assertEquals(webDriver.findElement(titleName).getText().contains("Apple"), true);
*/
    }

    public void sortViewChange() {
        Log4Test.info("View Change Choice");
        webDriver.findElement(arrowSortView).click();
    }

    public void expensveCheapSortClick() {
        Log4Test.info("From Expensive To Cheap View");
        webDriver.findElement(expensiveCheapSort).click();
    }

    public void verifySearchedMacBookPresent() {
        Log4Test.info("Verification searched NoteBook Z0PU002JE is present");
        webDriver.findElement(searchedMacBookName_Z0PU002JE);
    }

    /* List<WebElement> allnotes = webDriver.findElements(searchedMacBookName_Z0PU002JE);
     int count = 0;

     for (int i = 0; i < allnotes.size(); i++) {
         if (allnotes.get(i).getText().contains("Apple MacBook Pro Retina 15\" (Z0PU002JE)")) {
             count++;
             searchedMacBook = allnotes.get(i);
         }
     }
     Assert.assertEquals(count, 1);

 }
*/
    public void macBookToComparisonAdding() {
        Log4Test.info("Searched NoteBook Z0PU002JE to comparison adding");
        webDriver.findElement(toComparisonCheckboxMacBookName_Z0PU002JE).click();
    }

    public void verifyMacBookZ0PU002JEToComparisonAdded() {
        Log4Test.info("Verification searched NoteBook Z0PU002JE to comparison added");
        webDriver.findElement(toComparisonAdded_Z0PU002JE);
    }

    public void verifySearchedMacBookPresentME294UA() {
        Log4Test.info("Verification searched NoteBook ME294UA is present");
        webDriver.findElement(searchedMacBookName_ME294UA);
    }

    public void macBookME294UAToComparisonAdding() {
        Log4Test.info("Searched NoteBook ME294UA to comparison adding");
        webDriver.findElement(toComparisonCheckboxMacBookName_ME294UA).click();
    }

    public void verifyMacBookME294UAndZ0PU002JEToComparisonAdded() {
        Log4Test.info("Verification both searched NoteBook Z0PU002JE  and NoteBook ME294UA to comparison added");
        Assert.assertTrue(webDriver.findElement(toComparisonAdded_ME294UA).getText().contains("Apple MacBook Pro Retina 15\" (ME294UA/A) Официальная гарантия!") && webDriver.findElement(toComparisonAdded_Z0PU002JE).getText().contains("Apple MacBook Pro Retina 15\" (Z0PU002JE) Официальная гарантия!"));
    }
public ComparisonPage comparisonPageClick(){
    Log4Test.info("To ComparisonPage switch");
    webDriver.findElement(toComparisonClick_Z0PU002JE).click();
    return new ComparisonPage();
}
}
